package io.renren.modules.generator.service.impl;

import io.renren.modules.generator.entity.EcharsData;
import io.renren.modules.generator.entity.VisitNum;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.SysLogininforDao;
import io.renren.modules.generator.entity.SysLogininforEntity;
import io.renren.modules.generator.service.SysLogininforService;


@Service("sysLogininforService")
public class SysLogininforServiceImpl extends ServiceImpl<SysLogininforDao, SysLogininforEntity> implements SysLogininforService {

    @Autowired
    private  SysLogininforDao sysLogininforDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<SysLogininforEntity> page = this.page(
                new Query<SysLogininforEntity>().getPage(params),
                new QueryWrapper<SysLogininforEntity>().like(StringUtils.isNotBlank(key),"user_name",key).orderByDesc("info_id")
        );

        return new PageUtils(page);
    }

    @Override
    public int[] selectVisitorsOfMonth(String yearNum) {
        int[] selectVisitorsOfMonthData = new int[12];
        for (int i = 1; i <= 12; i++) {
            Integer integer = this.sysLogininforDao.selectVisitorsOfMonth(i + "", yearNum);
//            selectVisitorsOfMonthData.add(integer);
            selectVisitorsOfMonthData[i-1]=integer;
        }
       return  selectVisitorsOfMonthData;
    }

    @Override
    public List<EcharsData> selectProvinceAndNum() {
        List<EcharsData> provinceNumData = sysLogininforDao.selectProvinceAndNum();
        return provinceNumData;
    }

    @Override
    public VisitNum getVisitNum(){
       Integer todayVisitNum=sysLogininforDao.getTodayVisitNum();
        Integer allVisitNum = sysLogininforDao.getAllVisitNum();
        VisitNum visitNum = new VisitNum();
        visitNum.setAllNum(allVisitNum);
        visitNum.setTodayNum(todayVisitNum);
        return visitNum;
    }

}
